package com.cloudsigns.factorymanager2;

import android.app.Application;
import android.app.Service;
import android.os.Vibrator;
import android.util.Log;

import com.baidu.mapapi.SDKInitializer;
import com.cloudsigns.factorymanager2.engineering.bean.AccountInfoBean;
import com.cloudsigns.factorymanager2.produce.utils.SharedPreferencesUtil;
import com.cloudsigns.factorymanager2.service.LocationService;

/**
 * Created by tony on 2018/2/9.
 */

public class MyApplicaton extends Application {
    private static MyApplicaton application = null;
    private String token = "";
    private AccountInfoBean accountInfoBean;

    private LocationService locationService;
    private Vibrator mVibrator;

    private SharedPreferencesUtil mSpUtil;
    public static final String SP_FILE_NAME = "push_msg_sp";

    @Override
    public void onCreate() {
        super.onCreate();

        Log.e("request","MyApplicaton onCreate:");

        application = this;

        /***
         * 初始化定位sdk，建议在Application中创建
         */
        locationService = new LocationService(getApplicationContext());
        mVibrator = (Vibrator) getApplicationContext().getSystemService(Service.VIBRATOR_SERVICE);
        SDKInitializer.initialize(getApplicationContext());


        mSpUtil = new SharedPreferencesUtil(MyApplicaton.this, SP_FILE_NAME);
    }

    synchronized public static MyApplicaton getApplication() {
        return application;
    }

    public String getToken() {
        Log.e("request","token:" + token);
        return token;
    }

    public void setToken(String token) {
        this.token = token;
        Log.e("request","set token:" + token);
    }

    public AccountInfoBean getAccountInfoBean() {
        return accountInfoBean;
    }

    public void setAccountInfoBean(AccountInfoBean accountInfoBean) {
        this.accountInfoBean = accountInfoBean;
    }

    public synchronized SharedPreferencesUtil getSpUtil() {
        if (mSpUtil == null)
            mSpUtil = new SharedPreferencesUtil(this, SP_FILE_NAME);
        return mSpUtil;
    }
}
